package com.isunland.managesystem.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseButterKnifeAdapter;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.entity.ProductLedgerOriginal.ProductLedgerContent;
import com.isunland.managesystem.utils.MyStringUtil;
import com.isunland.managesystem.widget.CustomTextView;
import java.util.ArrayList;

//public class ProductCatalogListAdapter extends ArrayAdapter<ProductLedgerContent> {
//  private static class ViewHolder {
//    public final LinearLayout rootView;
//    public final TextView tvProductName;
//    public final TextView tvStandardPurchase;
//    public final TextView tvProductType;
//
//    private ViewHolder(LinearLayout rootView, TextView tvProductName, TextView tvStandardPurchase,
//        TextView tvProductType) {
//      this.rootView = rootView;
//      this.tvProductName = tvProductName;
//      this.tvStandardPurchase = tvStandardPurchase;
//      this.tvProductType = tvProductType;
//    }
//
//    public static ViewHolder create(LinearLayout rootView) {
//      TextView tvProductName = (TextView) rootView.findViewById(R.id.tv_product_name);
//      TextView tvStandardPurchase = (TextView) rootView.findViewById(R.id.tv_standard_purchase);
//      TextView tvProductType = (TextView) rootView.findViewById(R.id.tv_product_type);
//      return new ViewHolder(rootView, tvProductName, tvStandardPurchase, tvProductType);
//    }
//  }
//
//  @Override public View getView(int position, View convertView, ViewGroup parent) {
//    final ViewHolder vh;
//    if (convertView == null) {
//      View view = mInflater.inflate(R.layout.adapter_productcatalog_list, parent, false);
//      vh = ViewHolder.create((LinearLayout) view);
//      view.setTag(vh);
//    } else {
//      vh = (ViewHolder) convertView.getTag();
//    }
//
//    ProductLedgerContent item = getItem(position);
//    if (item.getProductName() != null) {
//      vh.tvProductName.setText(item.getProductName().toString());//产品名称
//    } else {
//      vh.tvProductName.setText("");//产品名称
//    }
//    if (item.getPurchasePrice() != null) {
//      vh.tvStandardPurchase.setText(item.getPurchasePrice().toString());//标准采购价
//    } else {
//      vh.tvStandardPurchase.setText("");//标准采购价
//    }
//    if (item.getMaterialKindCode() != null) {
//      vh.tvProductType.setText(item.getMaterialKindCom().toString());//产品类别
//    } else {
//      vh.tvProductType.setText("");//产品类别
//    }
//    return vh.rootView;
//  }
//
//  private LayoutInflater mInflater;
//
//  // Constructors
//  public ProductCatalogListAdapter(Context context, List<ProductLedgerContent> objects) {
//    super(context, 0, objects);
//    this.mInflater = LayoutInflater.from(context);
//  }
//
//  public ProductCatalogListAdapter(Context context, ProductLedgerContent[] objects) {
//    super(context, 0, objects);
//    this.mInflater = LayoutInflater.from(context);
//  }
//
//  @Override public boolean isEmpty() {
//    return false;
//  }
//}

public class ProductCatalogListAdapter extends BaseButterKnifeAdapter<ProductLedgerContent> {

  private Context context;

  public ProductCatalogListAdapter(BaseVolleyActivity context,
      ArrayList<ProductLedgerContent> objects) {
    super(context, objects);
    this.context=context;
  }

  @Override protected int setLayoutId() {
    return R.layout.adapter_out_list;
  }

  @NonNull @Override protected BaseViewHolder initHolder(View convertView) {
    return new ViewHolder(convertView);
  }

  @Override
  protected void initView(ProductLedgerContent item, BaseViewHolder baseHolder, int position) {
    ViewHolder holder = (ViewHolder) baseHolder;

    holder.tvTitle1.setVisibility(View.GONE);
    holder.tvStatus.setVisibility(View.GONE);
    holder.tvTitle2.setText(item.getProductName());//产品名称
    holder.tvContent1.setText(item.getMaterialKindCom());//物料类别
    holder.tvContent2.setText(MyStringUtil.connect(context.getResources().getString(R.string.standard_purchase),
        item.getPurchasePrice()));//价格
    holder.ivLogo.setText(MyStringUtil.substring(item.getProductName(), 0, 2));
  }

  @Override public boolean isEmpty() {
    return false;
  }

  protected class ViewHolder extends BaseViewHolder {
    @BindView(R.id.iv_logo) CustomTextView ivLogo;
    @BindView(R.id.tv_title1) TextView tvTitle1;
    @BindView(R.id.tv_status) TextView tvStatus;
    @BindView(R.id.tv_title2) TextView tvTitle2;
    @BindView(R.id.tv_content1) TextView tvContent1;
    @BindView(R.id.tv_content2) TextView tvContent2;

    ViewHolder(View view) {
      super(view);
      ButterKnife.bind(this, view);
    }
  }
}